<template>
  <div class="container">
    <div class="main-container">
      <!-- 日期导航 -->
      <div class="date-wrapper flex-sb">
        <div class="arrow"></div>
        <div class="date-list">
          <div v-for="item in schedules" :class="{ 'date-item': true, 'flex-cc': true, active: item.day === active }" @click="onChangeDate(item.day)">
            <div class="date-week">{{ item.week }}</div>
            <div class="date-divider"></div>
            <div class="f20">{{ item.day }}</div>
          </div>
        </div>
        <div class="arrow"></div>
      </div>

      <!-- 日程时间轴 -->
      <div class="sch-wrapper">
        <div ref="schInner" class="sch-inner">
          <div class="time-list" v-for="subject in schedule.subjects">
            <div class="timeline-bold f16 mb5 ml15">{{ subject.title }}</div>
            <div class="timeline-desc mb10 ml15">{{ subject.brief }}</div>
            <a-timeline mode="left" labelPosition="relative">
              <a-timeline-item v-for="item in subject.items" dotColor="#ba1a2d" dotType="hollow" lineColor="#edc3c7">
                <template #label>
                  <span class="timeline-bold">{{ item.time }}</span>
                </template>
                <template #dot>
                  <icon-record :style="dotStyle" size="18px" />
                </template>
                <div v-html="item.title" class="timeline-bold"></div>
                <div v-html="item.brief" class="timeline-desc"></div>
              </a-timeline-item>
            </a-timeline>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { IconRecord } from "@arco-design/web-vue/es/icon";
import request from "@/utils/http";
import type { DaySchedule, ScheduleList, ScheduleView } from "@/types/schedule";

const active = ref("");
const schInner = ref();

const schedules = ref<ScheduleList>([]);
const schedule = ref<DaySchedule>({
  id: null,
  day: "",
  week: "",
  subjects: [],
});

const dotStyle = ref({
  color: "#ba1a2d",
});

/**
 * 切换日期
 * @param day
 */
const onChangeDate = (day: string) => {
  if (schInner.value) {
    schInner.value.scrollTop = 0;
  }

  const list = schedules.value.filter((f) => f.day === day);
  if (list && list.length === 1) {
    schedule.value = list[0];
  }
  active.value = schedule.value.day;
};

const loadData = async () => {
  const { data } = await request<ScheduleView>({
    url: `/api/weapp/banquet/schedule`,
    method: "GET",
  });
  schedules.value = data.schedules;
  schedule.value = schedules.value[0];
  active.value = schedule.value.day;
};

onMounted(() => {
  loadData();
});
</script>

<style lang="less" scoped>
.container {
  height: 100vh;
  overflow: hidden;
}

.main-container {
  box-sizing: border-box;
  padding: 0 10px;
  width: 100%;
  height: 100%;
}

.date-wrapper {
  position: relative;
  border-radius: 15px;
  overflow: hidden;
  width: 100%;
  box-shadow: 10px 10px 30px rgba(65, 65, 65, 0.3);
  background: #fcf2f0;
  margin-top: 20px;
  flex: none;
  font-weight: bold;
  height: 144px;

  .date-list {
    width: 88%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .date-item {
    background-color: #ffffff;
    padding: 20px 16px;
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.25s;
    margin: 0 20px;

    .date-week {
      color: #a5a5a5;
    }

    .date-divider {
      height: 1px;
      width: 70%;
      background-color: #d1d1d1;
      margin: 8px 0;
    }

    &.active {
      background-color: var(--ui-THEME);
      color: #ffffff;
      padding: 30px 16px;
      font-size: 18px;

      .date-week {
        color: #ffffff;
      }
    }
  }
}

.sch-wrapper {
  margin-top: 20px;
  position: relative;
  background-color: #fcf2f0;
  border-radius: 15px;
  overflow: hidden;
  width: 100%;
  height: calc(100% - 300px);
  box-shadow: 10px 10px 30px rgba(65, 65, 65, 0.3);

  .sch-inner {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    height: 100%;
    width: 100%;

    scrollbar-color: #ba1a2d #f0f0f0;
    scrollbar-width: thin;

    &::-webkit-scrollbar {
      width: 3px;
    }

    &::-webkit-scrollbar-track {
      background: #ffffff;
    }

    &::-webkit-scrollbar-thumb {
      background: #ba1a2d;
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb:hover {
      background: #a31728;
    }

    .time-list {
      padding: 15px 20px 15px 0;
    }

    .timeline-bold {
      color: #6b3e43;
      font-weight: bold;
    }

    .timeline-desc {
      color: #6b3e43;
      font-size: 12px;
      padding-bottom: 5px;
    }
  }
}
</style>
